<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>js中的节流和防抖</title>
</head>
<body>
  <div class="debounce">
    <input type="text" id="dInput" />   
  </div>
  <script>
    const dInput = document.querySelector('#dInput')
    dInput.oninput = debounce(function() {
      console.log(this.value)
    }, 500)
    function debounce(fn, t = 300) {
      let timer
      return function() {
        let _this = this
        let args = arguments
        timer && clearTimeout(timer)
        timer = setTimeout(() => {
          fn.apply(_this, args)
        }, t)
      }
    }
  </script>
</body>
</html>